define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'union/daily2/index',
                    table: 'guild_account_daily',
                },
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: true,
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {
                            field: 'dt',
                            title: __('日期'),
                            formatter: Table.api.formatter.datetime, datetimeFormat:"YYYYMMDD",
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                        },

                        {field: 'voice_turnover', title: __('语音总流水'), operate: false},
                        {field: 'video_turnover', title: __('视频总流水'), operate: false},
                        {field: 'gift_turnover', title: __('普通礼物总流水'), operate: false},
                        {field: 'free_turnover', title: __('福利总流水'), operate: false},
                        {field: 'msg_turnover', title: __('私信总流水'), operate: false},
                        {field: 'active_host_num', title: __('活跃女用户数量'), operate: false},
                        {field: 'income_host_num', title: __('收益女用户数量'), operate: false},
                        // {field: 'host_share_income', title: __('女用户分成'), operate: false},
                        {field: 'total_turnover', title: __('超推总流水'), operate: false},
                        {field: 'child_sum', title: __('超推分成'), operate: false},
                        {field: 'invite_income', title: __('邀请充值返利'), operate: false},
                        {field: 'guild_share_income', title: __('超推分成'), operate: false},
                        {field: 'count_sum', title: __('超推总分成'), operate: false},
                        {field: 'out_status', title: __('提现状态'),searchList: {'0' : '未提现','1' :'已提现','2':'申请中','3':'申请失败'}, formatter: Table.api.formatter.normal},

                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $(".btn-out").click(function() {
                var screen_width = window.screen.width;
                var screen_height = window.screen.height;

                var today = new Date();
                var week = today.getDay();
                if (week != 1 && week != 4) {
                    layer.msg('提现时间固定为周一、周四',{icon:2});
                    return ;
                }
                var width = '500px';
                var height = '550px';
                //根据屏幕分辨率判断是否是手机
                if(screen_width < 500){
                    width = screen_width - 100 +"px";
                    height = screen_height - 200 + "px";
                }

                layer.open({
                    type: 1,
                    skin: "layui-layer-molv",
                    area: [width, height],
                    content: $("#layui"),
                    btn: ['确定','取消'] //按钮
                    ,yes: function(index, layero){
                        //按钮【按钮一】的回调
                        if ($("#username").val() !='' && $("#idcard").val()!='' && $("#payment").val() !='' ){
                            if ($("#out_type").val() == 2 && $("#bank_name").val() == ''){
                                layer.msg('具体提现信息不能为空', {icon: 6});
                                return false;
                            }
                            $.ajax({
                                type: "POST",
                                url: "union/daily2/cash_out",
                                data: {'payment':$("#payment").val(),'out_type':$("#out_type").val(),'username':$("#username").val(),'idcard':$("#idcard").val(),'bank_name':$("#bank_name").val()},
                                dataType: "json",
                                success: function(data){
                                    // if (data.ret == '0'){
                                    layer.msg(data.msg, {icon: 1},function (){
                                        location.reload();
                                    });
                                    // }
                                }
                            });
                        }else{
                            layer.msg('具体提现信息不能为空', {icon: 6})
                        }
                    }
                    ,btn2: function(index, layero){

                    }
                    ,end: function(){
                        //右上角关闭回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        // layer.close(index);
                        layer.close();
                    }
                });

                //
                // layer.confirm('您是确定要申请提现？', {
                //     btn: ['确定','取消'] //按钮
                // }, function(){
                //
                //
                // }, function(){
                //     layer.close();
                // });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});